import { defineStore } from "pinia";
import { store } from "@/store";
import type { appToken, userInfo } from "@/types/app"
import { getUsetInfo } from "@/api/user-app";
import router from "@/router";
interface app extends userInfo, appToken {

}
const appStore = defineStore({
    id: "app",
    state: (): app => ({
        token: "",
        account: "",
        address: "",
        updateTime: 0,
        id: 0,
        nickName: "",
        email: "",
        modelId: 0,
        modelName: ""
    }),
    actions: {
        setToken(token: string) {
            this.token = token
        },
        setUserInfo(res: userInfo) {
            this.account = res.account
            this.id = res.id
            this.account = res.account
            this.nickName = res.nickName
            this.modelId = res.modelId
            this.modelName = res.modelName
        }
    },
    getters: {
        getToken() {
            return this.token
        },
        getSlefUsetInfo(): userInfo {
            return {
                account: this.account,
                address: this.address,
                updateTime: this.updateTime,
                nickName: this.nickName,
                id: this.id,
                email: this.email,
                modelId:this.modelId,
                modelName:this.modelName
            }
        }

    }
})
export function useAppStoreWithOut() {
    return appStore(store);
}